# -*- coding: utf-8 -*-
import platform

import requests
import time
import hmac
import hashlib
import base64
import urllib.parse


class Send:

    @staticmethod
    def dingding(content):
        hostname = platform.node()  # 获取服务器名称
        timestamp = str(round(time.time() * 1000))
        secret = 'SEC2909dd83ac0ac44367936c52f0a1f68a0c37bac2a0251f229222c8587f97aa23'
        secret_enc = secret.encode('utf-8')
        string_to_sign = '{}\n{}'.format(timestamp, secret)
        string_to_sign_enc = string_to_sign.encode('utf-8')
        hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
        sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
        nowTime = time.strftime("%H:%M:%S", time.localtime())
        send_url = f'https://oapi.dingtalk.com/robot/send?access_token=fcfb2ebbfe0cf5904be3ddf185d4c07a519a7dbf161ca69f3e6f6705658eaf53&timestamp={timestamp}&sign={sign}'
        send_data = {"msgtype": "text", "at": {"atMobiles": [15089823325]}, "text": {"content": f"{nowTime} 剪映-{hostname}: {content}"}}
        requests.request('post', url=send_url, json=send_data)

    @staticmethod
    def qywxmsg(content):
        hostname = platform.node()  # 获取服务器名称
        nowTime = time.strftime("%H:%M:%S", time.localtime())
        send_url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=e774d10c-e2a5-486c-8e98-2a732ad42c56'
        send_data = {"msgtype": "text", "text": {"content": f"{nowTime} {hostname}：{content}"}}
        requests.request('post',  url=send_url, json=send_data)



if __name__ == '__main__':
    Send.qywxmsg('test')